/*
    api:"查询职位类型"
    name:"陈小洋"
    time：2021.1.24
* */
const PostType = require('../../../control/PostType/PostType')
const tools = require('../../../tools/public');
/**
 * @api {post} /postType/selPostType 2.查询职位类型
 * @apiGroup PostType
 *
 * @apiParam {Number} [PageNumber] 页码(默认为0)
 * @apiParam {Number} [PageSize]   分页大小(默认为100)
 * @apiParam {Number} [level] 职位层级  已经改成全部一次性返回出去
 * @apiParam {String} [PostTypeName] 职位名字（支持模糊查询）
 * @apiParam {String} [PostTypeDescribe] 职位描述(支持模糊查询)
 *
 * @apiParamExample {json} Request-Example
 *{
 *
 *}
 * @apiSuccessExample  {json} Response-Example
 * {
 *   "code": 200,
 *   "msg": "查询成功！"
 *   }
 */
module.exports = async function (req, res, next) {
    let {PageNumber, PageSize,level} = req.body, result = null;
    PageNumber = PageNumber || 0
    PageSize = PageSize || 100,
        result = null;
    try {
        /******    处理参数为空的数据 不传给数据库    ******/
        let SelJson = {}
        let celue = ['level']
        for (let i in celue) {
            req.body[celue[i]] ? SelJson[celue[i]] = req.body[celue[i]] : ""
        }
        /*****    处理参数的模糊查询    ******/
        let like_Json = {}
        let like_celue = ['PostTypeName', 'PostTypeDescribe']
        for (let i in like_celue) {
            req.body[like_celue[i]] ? like_Json[like_celue[i]] = new RegExp(`${req.body[like_celue[i]]}`) : ""
        }

        result = await PostType.Sel(Number(PageNumber),Number(PageSize),Object.assign(SelJson, like_Json));
        let total = await PostType.Sel_Count(Object.assign(SelJson, like_Json))
        res.send(tools.ReturnData(200, '查询成功！', result, total));
    } catch (e) {
        console.log(e)
        return res.send(tools.ReturnData(500, '系统内部错误！'));
    }
};